package com.zis.auction.controller;

import com.zis.auction.model.Carousel;
import com.zis.auction.service.ICarouselInter;
import com.zis.common.AuctProperties;
import com.zis.core.SearchParams;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by wangshen 2018/1/3
 */
@RestController
@RequestMapping("/api/auction/carousel")
public class CarouselController {

    @Autowired
    private ICarouselInter carouselInter;


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public PageQuery<Carousel> findByPage(@RequestBody SearchParams params) throws Exception {
        return carouselInter.findByPage(params);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String insert(HttpServletRequest request, @RequestBody Carousel carousel) throws Exception {
        carousel.setCreateUser(request.getAttribute("code").toString());
        return carouselInter.insert(carousel);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public String update(HttpServletRequest request, @RequestBody Carousel carousel) throws Exception {
        carousel.setUpdateUser(request.getAttribute("code").toString());
        return carouselInter.update(carousel);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String delete(@PathVariable("id") String id) throws Exception{
        return carouselInter.delete(id);
    }

    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Carousel select(@PathVariable("id") String id) throws Exception{
        return carouselInter.selectById(id);
    }
}
